package com.winning.sx.microframework.service.entity;


import com.winning.dapi.data.entity.DataTable;
import com.winning.sx.microframework.dao.entity.BaseConstType;
import com.winning.sx.microframework.model.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.Map;

@Service
public class EBaseConstTypeService {

    @Autowired
    private BaseConstType dao;

    public DataTable queryList(Map<String, String> param) throws CustomException {
        try {
            return dao.queryList(param);
        } catch (SQLException e) {
            throw new CustomException(1, e.getMessage());
        }
    }


    public boolean save(Map<String, String> param) throws CustomException {
        try {
            if (param.get("id") != null && !"".equals(param.get("id"))) {
                return dao.update(param);

            } else {
                return dao.insert(param);
            }
        } catch (SQLException e) {
            throw new CustomException(2, e.getMessage());
        }
    }

    public boolean delete(Map<String, String> param) throws CustomException {
        try {
            return dao.delete(param);
        } catch (SQLException e) {
            throw new CustomException(2, e.getMessage());
        }
    }
}
